package com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Statistics.HomeWorkRank;

import android.os.Bundle;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.tnot.R;
import com.example.tnot.Teacher.BaseFragment.BaseBackFragment;
import com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Statistics.HomeWorkRank.Adapter.homeworkRankAdapter;
import com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Statistics.HomeWorkRank.ItemBean.HomeWorkRank;

import java.util.ArrayList;
import java.util.List;

public class HomeWorkRankFragment extends BaseBackFragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;
    View view;
    ImageView back;
    RecyclerView rv_homeworkRank;
    private List<HomeWorkRank> RankData;
    private homeworkRankAdapter adapter;
    private boolean showFinishData = true;
    TextView tv_finishRate,tv_accuracyRate;


    public HomeWorkRankFragment() {
    }
    public static HomeWorkRankFragment newInstance(String param1, String param2) {
        HomeWorkRankFragment fragment = new HomeWorkRankFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.course_home_work_rank_fragment, container, false);


        RankData = new ArrayList<>();
        InitData();
        setupAccuracyClickListener();
        setupFinishClickListener();
        rv_homeworkRank = view.findViewById(R.id.rv_homeworkRank);
        adapter = new homeworkRankAdapter(RankData);
        rv_homeworkRank.setAdapter(adapter);

        back = view.findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigateUp();
            }
        });
        return view;
    }

    private void InitData() {
        RankData.add(new HomeWorkRank("张三","计算机科学与技术","完成度90%",R.drawable.example_face));
        RankData.add(new HomeWorkRank("张三","数科2301","完成度100%",R.drawable.example_face));
        RankData.add(new HomeWorkRank("张三","计算机科学技术","完成度80%",R.drawable.example_face));

    }

    // 切换数据显示类型
    private void switchDataType() {
        showFinishData = !showFinishData;
        adapter.updateDataType(showFinishData);
    }

    // 设置正确率TextView的点击事件
    private void setupAccuracyClickListener() {
        tv_finishRate = view.findViewById(R.id.tv_finishRate); // 假设这是顶部的正确率标题
        tv_finishRate.setOnClickListener(v -> {
            showFinishData = false;
            adapter.updateDataType(showFinishData);
        });
    }

    // 设置完成度TextView的点击事件
    private void setupFinishClickListener() {
        tv_accuracyRate = view.findViewById(R.id.tv_accuracyRate); // 假设这是顶部的完成度标题
        tv_accuracyRate.setOnClickListener(v -> {
            showFinishData = true;
            adapter.updateDataType(showFinishData);
        });
    }

}